//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
    components: {
      //动态扩充组件或组件路径
      //表单header、content、footer对应位置扩充的组件
      gridHeader: "", //{ template: "<div>扩展组xx件</div>" },
      gridBody: "",
      gridFooter: "",
      //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
      modelHeader: "",
      modelBody: "",
      modelFooter: ""
    },
    buttons: { view: [], box: [], detail: [] }, //扩展的按钮
    methods: {
      //事件扩展
      getFormOption(field) {
        let option;
        this.editFormOptions.forEach(x => {
          x.forEach(item => {
            if (item.field == field) {
              option = item;
            }
          });
        });
        return option;
      },
      rowClick({ row, column, event }) {
        //查询界面table点击行选中当前行
        this.$refs.table.$refs.table.toggleRowSelection(row);
        return true;
      },
      onInit() {
        // this.single = true;
        // this.textInline = true;
        // this.ck = false;
        //;
        //this.maxBtnLength = 5;
        this.boxOptions.height = 710;
        let x = this.getFormOption("name");
        x.onInput = val => {
          this.editFormFileds.code = this.base.chineseToPinYin(val);
        };
        var paytype = this.getFormOption("type");

        var mer_idOption = this.getFormOption("mer_id");
        var mch_idOption = this.getFormOption("mch_id");
        var mch_keyOption = this.getFormOption("mch_key");
        var key_pathOption = this.getFormOption("key_path");
        var pathOption = this.getFormOption("path");
        var hank_app_idOption = this.getFormOption("hank_app_id");
        var apigw_public_keyOption = this.getFormOption("apigw_public_key");
        var my_private_keyOption = this.getFormOption("my_private_key");
        var mer_prtcl_noOption = this.getFormOption("mer_prtcl_no");
        let app_secret = this.getFormOption("app_secret");
        let merchant_private_key = this.getFormOption("merchant_private_key");
        let merchant_public_key = this.getFormOption("merchant_public_key");
        let alipay_public_key = this.getFormOption("alipay_public_key");
        let free_rate = this.getFormOption("free_rate");
        paytype.onChange = (val, item) => {
          app_secret.hidden = true;
          app_secret.required = false;
          if (val == 1) {
            mch_idOption.hidden = false;
            mch_keyOption.hidden = false;
            key_pathOption.hidden = false;
            pathOption.hidden = false;
            hank_app_idOption.hidden = true;
            apigw_public_keyOption.hidden = true;
            my_private_keyOption.hidden = true;
            mer_prtcl_noOption.hidden = true;
            mer_idOption.hidden = true;
            merchant_private_key.hidden = true;
            merchant_public_key.hidden = true;
            alipay_public_key.hidden = true;
          } else if (val == 2) {
            mch_idOption.hidden = true;
            mch_keyOption.hidden = true;
            key_pathOption.hidden = true;
            pathOption.hidden = true;
            merchant_private_key.hidden = true;
            merchant_public_key.hidden = true;
            alipay_public_key.hidden = true;
            hank_app_idOption.hidden = false;
            apigw_public_keyOption.hidden = false;
            my_private_keyOption.hidden = false;
            mer_prtcl_noOption.hidden = false;
            mer_idOption.hidden = false;
          } else if (val == 7) {
            mch_idOption.hidden = true;
            mch_keyOption.hidden = true;
            key_pathOption.hidden = true;
            pathOption.hidden = true;
            app_secret.hidden = true;
            app_secret.required = false;
            apigw_public_keyOption.hidden = true;
            my_private_keyOption.hidden = true;
            mer_prtcl_noOption.hidden = true;
            mer_idOption.hidden = true;
            hank_app_idOption.hidden = true;
            merchant_private_key.hidden = false;
            merchant_public_key.hidden = false;
            alipay_public_key.hidden = false;
          } else if (val == 3) {
            mch_idOption.hidden = false;
            mch_keyOption.hidden = true;
            key_pathOption.hidden = true;
            pathOption.hidden = true;
            hank_app_idOption.hidden = false;
            apigw_public_keyOption.hidden = false;
            // 公钥设置为必填项
            apigw_public_keyOption.required = true;
            // 私钥设置为必填项
            my_private_keyOption.required = true;
            my_private_keyOption.hidden = false;
            mer_prtcl_noOption.hidden = true;
            mer_idOption.hidden = true;
            merchant_private_key.hidden = true;
            merchant_public_key.hidden = true;
            alipay_public_key.hidden = true;
          } else if (val == 9) {
            mch_idOption.hidden = false;
            mch_keyOption.hidden = false;
            key_pathOption.hidden = false;
            pathOption.hidden = true;
            hank_app_idOption.hidden = true;
            apigw_public_keyOption.hidden = false;
            my_private_keyOption.hidden = false;
            mer_prtcl_noOption.hidden = true;
            mer_idOption.hidden = false;
            merchant_private_key.hidden = true;
            merchant_public_key.hidden = true;
            alipay_public_key.hidden = true;
            free_rate.hidden = true;
          } else {
            mch_idOption.hidden = false;
            mch_keyOption.hidden = false;
            key_pathOption.hidden = false;
            pathOption.hidden = false;
            hank_app_idOption.hidden = false;
            apigw_public_keyOption.hidden = false;
            my_private_keyOption.hidden = false;
            mer_prtcl_noOption.hidden = false;
            mer_idOption.hidden = false;
            merchant_private_key.hidden = true;
            merchant_public_key.hidden = true;
            alipay_public_key.hidden = true;
            free_rate.hidden =false;
            // 公钥设置为非必填项
            apigw_public_keyOption.required = false;
            // 私钥设置为非必填项
            my_private_keyOption.required = false;
          }
        };
      },
      modelOpenBefore(row) {
        // if (this.currentAction != 'Add') {
        //   console.log("编辑",row)
        //   var objArr= []
        // for(let i in row) {
        //   // arr.push (obj[i] )  //返回属性值
        //   if(row[i] ==null ||row[i]==""||row[i]=="1")
        //   objArr.push (i)  //返回键名
        // }
        // console.log(objArr,"objArr")
        // }
      },
      modelOpenAfter(row) {
        var mer_idOption = this.getFormOption("mer_id");
        var mch_idOption = this.getFormOption("mch_id");
        var mch_keyOption = this.getFormOption("mch_key");
        var key_pathOption = this.getFormOption("key_path");
        var pathOption = this.getFormOption("path");
        var hank_app_idOption = this.getFormOption("hank_app_id");
        var apigw_public_keyOption = this.getFormOption("apigw_public_key");
        var my_private_keyOption = this.getFormOption("my_private_key");
        var mer_prtcl_noOption = this.getFormOption("mer_prtcl_no");
        let app_secret = this.getFormOption("app_secret");
        let merchant_private_key = this.getFormOption("merchant_private_key");
        let merchant_public_key = this.getFormOption("merchant_public_key");
        let alipay_public_key = this.getFormOption("alipay_public_key");
        let free_rate = this.getFormOption("free_rate");
        app_secret.hidden = true;
        app_secret.required = false;
        if (this.currentAction == "Add") {
          mch_idOption.hidden = false;
          mch_keyOption.hidden = false;
          key_pathOption.hidden = false;
          pathOption.hidden = false;
          hank_app_idOption.hidden = false;
          apigw_public_keyOption.hidden = false;
          my_private_keyOption.hidden = false;
          mer_prtcl_noOption.hidden = false;
          mer_idOption.hidden = false;
          merchant_private_key.hidden = true;
          merchant_public_key.hidden = true;
          alipay_public_key.hidden = true;
        } else {
          switch (row.type) {
            case 1:
              mch_idOption.hidden = false;
              mch_keyOption.hidden = false;
              key_pathOption.hidden = false;
              pathOption.hidden = false;
              hank_app_idOption.hidden = true;
              apigw_public_keyOption.hidden = true;
              my_private_keyOption.hidden = true;
              mer_prtcl_noOption.hidden = true;
              mer_idOption.hidden = true;
              merchant_private_key.hidden = true;
              merchant_public_key.hidden = true;
              alipay_public_key.hidden = true;
              break;
            case 2:
              mch_idOption.hidden = true;
              mch_keyOption.hidden = true;
              key_pathOption.hidden = true;
              pathOption.hidden = true;
              merchant_private_key.hidden = true;
              merchant_public_key.hidden = true;
              alipay_public_key.hidden = true;
              hank_app_idOption.hidden = false;
              apigw_public_keyOption.hidden = false;
              my_private_keyOption.hidden = false;
              mer_prtcl_noOption.hidden = false;
              mer_idOption.hidden = false;
              break;
            case 7:
              mch_idOption.hidden = true;
              mch_keyOption.hidden = true;
              key_pathOption.hidden = true;
              pathOption.hidden = true;
              app_secret.hidden = true;
              app_secret.required = false;
              apigw_public_keyOption.hidden = true;
              my_private_keyOption.hidden = true;
              mer_prtcl_noOption.hidden = true;
              mer_idOption.hidden = true;
              hank_app_idOption.hidden = true;
              merchant_private_key.hidden = false;
              merchant_public_key.hidden = false;
              alipay_public_key.hidden = false;
              break;
            case 3:
              mch_idOption.hidden = false;
              mch_keyOption.hidden = true;
              key_pathOption.hidden = true;
              pathOption.hidden = true;
              hank_app_idOption.hidden = false;
              apigw_public_keyOption.hidden = false;
              my_private_keyOption.hidden = false;
              mer_prtcl_noOption.hidden = true;
              mer_idOption.hidden = true;
              merchant_private_key.hidden = true;
              merchant_public_key.hidden = true;
              alipay_public_key.hidden = true;
              // 编辑设置为必填项
              apigw_public_keyOption.required = true;
              my_private_keyOption.required = true;
              break;
            case 9:
              mch_idOption.hidden = true;
              mch_keyOption.hidden = true;
              key_pathOption.hidden = true;
              pathOption.hidden = true;
              hank_app_idOption.hidden = true;
              apigw_public_keyOption.hidden = false;
              my_private_keyOption.hidden = false;
              mer_prtcl_noOption.hidden = true;
              mer_idOption.hidden = true;
              merchant_private_key.hidden = true;
              merchant_public_key.hidden = true;
              alipay_public_key.hidden = true;
              free_rate.hidden = true;
              break;
            default:
              mch_idOption.hidden = false;
              mch_keyOption.hidden = false;
              key_pathOption.hidden = false;
              pathOption.hidden = false;
              hank_app_idOption.hidden = false;
              apigw_public_keyOption.hidden = false;
              my_private_keyOption.hidden = false;
              mer_prtcl_noOption.hidden = false;
              mer_idOption.hidden = false;
              merchant_private_key.hidden = true;
              merchant_public_key.hidden = true;
              alipay_public_key.hidden = true;
              free_rate.hidden = false;
              break;
          }
          // console.log(row,"row1")
          // delete row.createID
          // delete row.modifierID
          // delete row.modifyDate
          // delete row.modifier
          // delete row.type
          // var objArr = [];
          // for (let i in row) {
          //   // arr.push (obj[i] )  //返回属性值
          //   if (row[i] == null || row[i] == "" ||row[i] == "1"||row[i] == undefined){
          //     objArr.push(i); //返回键名
          //     // console.log(this.getFormOption(i),i,row[i],"objArri");
          //     this.getFormOption(i).hidden=true
          //   }
          // }
          // console.log(objArr, "objArrkey");
        }
      }
    }
  };
  export default extension;
